﻿using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Table;
using POC.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace POC.Logger
{
    public class AzureAccount
    {
        StorageCredentials credential;
        public CloudStorageAccount CloudAccount {get;set;}
        public AzureAccount(string connectionStringName)
        {
            //string connectionString =  CloudConfigurationManager.GetSetting(connectionStringName);
            string connectionString2 = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            CloudAccount = CloudStorageAccount.Parse(connectionString2);
        }
        public AzureAccount(string accountName, string accountKey, bool isSecure = false)
        {   
            credential = new StorageCredentials(accountName, accountKey);
            var BlobUri = CallSetting.BuildUri(accountName, ConfigValueConstant.AzureStorageBlobUriString, isSecure);
            var QueueUri = CallSetting.BuildUri(accountName, ConfigValueConstant.AzureStorageQueueUriString, isSecure);
            var TableUri = CallSetting.BuildUri(accountName, ConfigValueConstant.AzureStorageTableUriString, isSecure);
            CloudAccount = new CloudStorageAccount(credential, BlobUri, QueueUri, TableUri);
        }
        public AzureAccount(bool local = false)
        {
            if (local == false)
            {
                credential = new StorageCredentials(CallSetting.Instance.AccountName, CallSetting.Instance.AccountKey);
                CloudAccount = new CloudStorageAccount(credential, CallSetting.Instance.BlobUri, CallSetting.Instance.QueueUri, CallSetting.Instance.TableUri);
            }
            else
            {
                CloudAccount = CloudStorageAccount.DevelopmentStorageAccount;
            }
        }       

    }
}
